import { AxiosPromise } from 'axios'
import { api } from '../boot/axios'
import { RepairOrderEDoc } from './type'

function url(s: string) {
  if (s==''){
    return ['/api/repairorderedocs', ''].join('/')
  }
  return ['/api/repairorderedocs', s.replace('/', ''), ''].join('/')
}


export function getRepairOrderEDocs(repair_order:number){
  /*
    get edocs of a repair order
  
    Args:
      repair_order: id of order
  
    Returns:
      list of edoc
  */
 return api({
  url: url('get_edocs_realtime'),
  method: 'post',
  data: {
    repair_order
  }
 }) as AxiosPromise<RepairOrderEDoc[]>
}

export function toggleEDocComplete(id:number){
  return api({
    url: url('toggle_complete'),
    method: 'post',
    data:{
      id
    }
  }) as AxiosPromise<RepairOrderEDoc>
}
